package com.study.entity.vo;

import com.study.entity.emuns.StatusCode;

public class Result<T> {
    // 是否成功
    private boolean success;
    // 状态码
    private int code;
    // 消息
    private String message;
    // 数据
    private T data;

    // 无参构造方法
    public Result() {
    }

    // 构造方法
    public Result(boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 静态方法：快速创建成功的 Result 对象
    public static <T> Result<T> ok(T data) {
        return new Result<T>(true, StatusCode.OK.getCode(), "操作成功", data);
    }

    // 静态方法：快速创建失败的 Result 对象
    public static <T> Result<T> error(int code, String message) {
        return new Result<>(false, code, message, null);
    }

    // Getter 和 Setter 方法
    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
